﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ServiceInterfaces.Headquarters;
using DTO.Common;
using System.Runtime.Serialization;
using System.Transactions;

namespace Teste
{
    class Program
    {

        static void Main(string[] args)
        {
            //AddSupplier();
            //AddProduct();
            //SellProduct();
            UpdateStock();
        }

        static void AddSupplier() 
        {
            ChannelFactory<IHeadquartersManagement> factory = new ChannelFactory<IHeadquartersManagement>("headquarter");
            IHeadquartersManagement headquarter = factory.CreateChannel();

            headquarter.AddSupplier(new Supplier { 
                Name = "Supplier1",
                Address = "Supplier 1 Address"
            });

            factory.Close();
        }

        static void AddProduct()
        {
            ChannelFactory<IHeadquartersManagement> factory = new ChannelFactory<IHeadquartersManagement>("headquarter");
            IHeadquartersManagement headquarter = factory.CreateChannel();
            headquarter.AddProduct(
                new Product
                {
                    Designation = "fdx",
                    Price = 10,
                    Stock = 20,
                    StockMin = 10,
                    Supplier = new Supplier
                    {
                        Number = 1
                    },
                    Type = ProductType.Man
                });

            factory.Close();
        }

        static void SellProduct()
        {
            ChannelFactory<IHeadquartersSales> factory = new ChannelFactory<IHeadquartersSales>("headquarterMSMQ");
            IHeadquartersSales headquarter = factory.CreateChannel();

            using (TransactionScope ts = new TransactionScope())
            {
                headquarter.SellProduct(2, 10);
                ts.Complete();
            }

            factory.Close();
        }

        static void UpdateStock()
        {
            ChannelFactory<IHeadquartersManagement> factory = new ChannelFactory<IHeadquartersManagement>("headquarter");
            IHeadquartersManagement headquarter = factory.CreateChannel();

            headquarter.UpdateStock(3, 20);

            factory.Close();
        }
    }
}
